var $, element, layer, laydate, form;
var today = DateUtils.dateFormat(new Date(), "yyyy-MM-dd"); // 今天的日期
var contractId = QueryUtils.GetQueryString("CONTRACT_ID");
var button = QueryUtils.GetQueryString("button");//按钮审核页面跳转
var checkType = QueryUtils.GetQueryString("type");
//alert(checkType);
layui.use(['jquery', 'element', 'layer', 'laydate', 'form', 'upload', 'table'], function () {
    // 加载元素控件
    $ = layui.jquery, element = layui.element, layer = layui.layer, laydate = layui.laydate, form = layui.form, table = layui.table;

    // 合同ID

    // var contractId = 'a6aa00c80df54b33a3e795174862e7f7';
    //初始化审核按钮是否有权限
    if ("shenhe" == button) {
        $(".shenhe").html(" <a class=\"layui-btn layui-btn-small\" onclick=\"operate.pass();\">通过</a>\n" +
            "            <a class=\"layui-btn layui-btn-small layui-btn-danger\" onclick=\"operate.reject(this);\">驳回</a>");
    }
    init.initContractInfo(contractId);

    //加载审核详细
    //操作详情
    var data = {};
    data.CONTRACT_ID = contractId;
    //alert(data.CONTRACT_ID);
    table.render({
        elem: '#historySH'
        , url: '/recordController/list'
        , where: data
        , cols: [[
            {field: 'DETAILS', event: 'setSign', title: '操作详情', width: 300}
            , {field: 'OPERATOR', event: 'setSign', title: '操作人', width: 150}
            , {field: 'OPERA_TIME', event: 'setSign', title: '操作时间', width: 150}

        ]]
        , id: ''
        , page: true
        , height: 'auto'
        , limit: '10'
        , size: 'sm' //小尺寸的表格
    });
});
/**
 * 初始化方法集合
 * 使用： init.function()
 * param: obj传this，调用该方法的对象
 *
 */
var init = {
    // 通过合同ID获取合同详情
    initContractInfo: function (id) {
        $.ajax({
            url: "/contract/info",
            data: {id: id},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    init.setValue(res.data);
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 赋值
    setValue: function (data) {
        // console.log(data);
        var contract = data.contract;
        var room = data.room;
        var bond = data.bond;
        var contact = data.contact;
        var discount = data.discount;
        var bill = data.bill;
        var property = data.property;
        var attachment = data.attachment;
        var initRead = data.initRead;
        var bl = data.BL;
        var throwLease = data.throwLease;

        $(".contract_num").html(contract.CONTRACT_NUM);
        $(".submit_person_name").html(contract.SUBMIT_PERSON_NAME);
        $(".con_date").html(contract.CON_DATE);

        $(".rooms").empty();
        var totalArea = 0;
        if (!!room) {
            for (var i = 0; i < room.length; i++) {
                var cq = "";
                if (room[i].PROPERTY_RIGHT_TYPE == "0") {
                    cq = "自有";
                } else if (room[i].PROPERTY_RIGHT_TYPE == "1") {
                    cq = "非自有";
                }
                var str = '<div class="unit-room">\n' +
                    '          <div class="unit-room-name">' + room[i].BUSINESS_NAME + ' / ' + room[i].BUILDING_NAME + ' / ' + room[i].ROOM_NUM + '(' + cq + ')' + '</div>\n' +
                    '          <div class="unit-room-area">\n' +
                    '              <span>' + room[i].ROOM_AREA + '</span>\n' +
                    '              ㎡\n' +
                    '          </div>\n' +
                    '      </div>';
                totalArea += Number(room[i].ROOM_AREA);
                $(".rooms").append(str);
            }
            $(".total-area").html(totalArea);
            $(".contract-area").html(contract.AREA);
            if (room[0].PROPERTY_RIGHT_TYPE == "1") {
                init.hideContractInfo();
            }
        }

        if (contract.LEASE == 0) {
            $(".legal_person_name").html(contract.LEGAL_PERSON_NAME);
            $(".legal_person_tel").html(contract.LEGAL_PERSON_TEL);
        } else if (contract.LEASE == 1) {
            $(".company_name_type").html("姓名：");
            $(".business_license_type").html("身份证号：");
            $(".legal_person").remove();
        }
        $(".company_name").html(contract.COMPANY_NAME);
        $(".byname").html(contract.BYNAME);
        $(".industry_name").html(contract.INDUSTRY_NAME);
        $(".business_license").html(contract.BUSINESS_LICENSE);
        $(".signer").html(contract.SIGNER);
        $(".signer_tel").html(contract.SIGNER_TEL);
        $(".contract_address").html(contract.CONTRACT_ADDRESS);
        $(".contract_info").html(contract.INFO);

        $(".contacts").empty();
        if (!!contact) {
            for (var i = 0; i < contact.length; i++) {
                var str = '<div class="layui-inline layui-inline-normal">\n' +
                    '          <label class="layui-form-label">联系人：</label>\n' +
                    '          <div class="layui-input-inline">\n' +
                    '              <span>' + contact[i].CONTACTS_NAME + '</span>\n' +
                    '          </div>\n' +
                    '      </div>\n' +
                    '      <div class="layui-inline layui-inline-short">\n' +
                    '          <label class="layui-form-label">联系电话：</label>\n' +
                    '          <div class="layui-input-inline">\n' +
                    '              <span>' + contact[i].CONTACTS_TEL + '</span>\n' +
                    '          </div>\n' +
                    '      </div>';
                $(".contacts").append(str);
            }
        }

        $(".con_hr_date").html(contract.CON_HR_DATE);
        $(".con_end_date").html(contract.CON_END_DATE);
        $(".con_ten_date").html(contract.CON_TEN_DATE);

        $(".pay-tx-days").html(contract.PAY_TX_DAYS);
        $(".end-tx-days").html(contract.END_TX_DAYS);
        $(".late-fee-days").html(contract.LATE_FEE_DAYS);
        if (!!contract.CON_OUTF_DATE) {
            var str = '<div><span>' + contract.CON_OUTF_DATE + '</span> 至 <span>' + DateUtils.addDay(-1, new Date(contract.CON_HR_DATE)) + '</span></div>';
            $(".con-mzq").append(str);
        }
        if (!!contract.CON_OUTL_DATE) {
            var str = '<div><span>' + DateUtils.addDay(1, new Date(contract.CON_END_DATE)) + '</span> 至 <span>' + contract.CON_OUTL_DATE + '</span></div>';
            $(".con-mzq").append(str);
        }
        if (!contract.CON_OUTF_DATE && !contract.CON_OUTL_DATE) {
            $(".con_mzq").remove();
        }
        $(".rent").html(contract.RENT);
        var unitHtmlStr = "";
        switch (Number(contract.UNIT)) {
            case 0:
                $(".unit").html("元/㎡·天");
                unitHtmlStr = "元/㎡·天";
                break;
            case 1:
                $(".unit").html("元/日");
                unitHtmlStr = "元/日";
                break;
            case 2:
                $(".unit").html("元/月");
                unitHtmlStr = "元/月";
                break;
            case 3:
                $(".unit").html("元/年");
                unitHtmlStr = "元/年";
                break;
            case 4:
                $(".unit").html("元");
                unitHtmlStr = "元";
                break;
            case 5:
                $(".unit").html("元/㎡·月");
                unitHtmlStr = "元/㎡·月";
                break;
            default:
                $(".unit").html("元/㎡·天");
                unitHtmlStr = "元/㎡·天";
                break;
        }
        // $(".bond").html(contract.BOND);
        $(".bonds").empty();
        if (!!bond) {
            for (var i = 0; i < bond.length; i++) {
                var str = '<div class="layui-input-inline">\n' +
                    '          <span>' + bond[i].BOND_NAME + ': ' + bond[i].BOND_MONEY + '元</span>\n' +
                    '      </div>';
                $(".bonds").append(str);
            }
        }

        if (contract.PAY_TYPE == 0) {

        } else if (contract.PAY_TYPE == 1) {

        }

        if (contract.PAY_DAY_MONTH == 0) {
            $(".payment_period").html(contract.PAYMENT_PERIOD + "日");
        } else {
            switch (contract.PAYMENT_PERIOD) {
                case 1:
                    $(".payment_period").html("月");
                    break;
                case 3:
                    $(".payment_period").html("季");
                    break;
                case 6:
                    $(".payment_period").html("半年");
                    break;
                case 12:
                    $(".payment_period").html("年");
                    break;
                default:
                    $(".payment_period").html(contract.PAYMENT_PERIOD + "月");
                    break;
            }
        }

        if (contract.PAY_TYPE == 0) {
            $(".ant_pay_day").html("提前" + contract.ANT_PAY_DAY + "天");
        } else if (contract.PAY_TYPE == 1) {
            $(".ant_pay_day").html("固定每月" + contract.ANT_PAY_DAY + "号");
        }

        if (contract.INCREAS_TYPE == 0) {
            $(".increas_type").html("原始租金递增");
        } else if (contract.INCREAS_TYPE == 1) {
            $(".increas_type").html("上年租金递增");
        }

        var contractLateFee = contract.LATE_FEE;
        if (!contractLateFee || contractLateFee == " - ") {
            contractLateFee = 0;
        }
        $(".late_fee").html("年租金的 " + contractLateFee + "%");

        $(".discounts").empty();
        if (!!discount) {
            for (var i = 0; i < discount.length; i++) {
                var znj = discount[i].LATE_FEE;
                if (!znj) {
                    znj = "0.00";
                }
                var str = '<div class="layui-input-inline">\n' +
                    '          <span>第' + TypeUtils.NumberToChinese(discount[i].FIRST_YEAR) + '年：' +
                    '递增率：' + discount[i].INCREAS_RATE + '%；' +
                    '折扣：' + discount[i].DISCOUNT + '折；' +
                    '折后价格：' + discount[i].DISCOUNT_RENT + unitHtmlStr + '；' +
                    '滞纳金：' + znj + '元/天。</span>\n' +
                    '      </div>';
                $(".discounts").append(str);
            }
        }

        if (!!bill) {
            for (var i = 0; i < bill.length; i++) {
                var fkfpStr = '';
                /*if (bill[i].PAY_TYPE == 0) {
                    fkfpStr = '按比例：' + bill[i].PAY_TYPE_PROPORTION + '%（' + bill[i].PAY_TYPE_MONEY + '元）开发票';
                } else if (bill[i].PAY_TYPE == 1) {
                    fkfpStr = '固定金额：' + bill[i].PAY_TYPE_MONEY + '元开发票';
                }*/
                if (bill[i].ALLOT_BILL == 0) {
                    fkfpStr += '开发票';
                } else if (bill[i].ALLOT_BILL == 1) {
                    fkfpStr += '不开发票';
                }
                var lateFee = bill[i].LATE_FEE;
                if (!lateFee || lateFee == " - ") {
                    lateFee = 0;
                }
                var billInfo = bill[i].INFO;
                if (!billInfo) {
                    billInfo = "";
                }
                if (!bill[i].END_DATE) {
                    bill[i].END_DATE = bill[i].START_DATE;
                }
                var str = '<li class="rent-detail-item">\n' +
                    '          <div>\n' +
                    '              <span>' + bill[i].START_DATE + ' - ' + bill[i].END_DATE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + bill[i].PAY_DATE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + bill[i].TOTAL_PRICE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + lateFee + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + bill[i].BILL_NAME + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + fkfpStr + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + billInfo + '</span>\n' +
                    '          </div>\n' +
                    '      </li>';
                $(".container-rent-detail-list").append(str);
            }
        }

        $(".property-info").empty();
        if (!!property) {
            for (var i = 0; i < property.length; i++) {
                // $(".property-fpzb").html(property[i].PROPERTY_FPZB);
                var sffs = '';
                var initReadStr = "";
                if (property[i].CHARGE_TYPE == 0) {
                    sffs = '固定价格';
                } else if (property[i].CHARGE_TYPE == 1) {
                    sffs = '抄表收费';
                    if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                        if (!!initRead) {
                            initReadStr += '<div class="layui-form-item">\n' +
                                '                                    <div class="layui-inline">\n' +
                                '                                        初始读数：\n' +
                                '                                    </div>\n' +
                                '                                    <div class="layui-inline">\n';
                            for (var j = 0; j < initRead.length; j++) {
                                if (property[i].PROPERTY_TYPE_ID == initRead[j].PROPERTY_TYPE_ID) {

                                    var blStr = '';

                                    if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e') {
                                        for (var k = 0; k < bl.length; k++) {
                                            if (initRead[j].HYDROPOWER_ID == bl[k].CODEID && !!bl[k].W_BL) {
                                                blStr += '<div>' + bl[k].ROOM_NUM + '所占比例：' + bl[k].W_BL + '%</div>';
                                            }
                                        }
                                    } else if (property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                        for (var k = 0; k < bl.length; k++) {
                                            if (initRead[j].HYDROPOWER_ID == bl[k].CODEID && !!bl[k].E_BL) {
                                                blStr += '<div>' + bl[k].ROOM_NUM + '所占比例：' + bl[k].E_BL + '%</div>';
                                            }
                                        }
                                    }

                                    initReadStr += '<div class="layui-input-inline" style="width: auto;">\n' +
                                        '               <span>' + initRead[j].CODE + ' 读数：' + initRead[j].INIT_READ + ' 日期：' + initRead[j].INIT_READ_TIME + '</span>\n' +
                                        blStr +
                                        '           </div><br>';
                                }
                            }
                            initReadStr += '                    </div>\n' +
                                '                                </div>';
                        }
                    }
                } else if (property[i].CHARGE_TYPE == 2) {
                    sffs = '按面积收费';
                } else if (property[i].CHARGE_TYPE == 3) {
                    sffs = '即时收费';
                    if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                        if (!!initRead) {
                            initReadStr += '<div class="layui-form-item">\n' +
                                '                                    <div class="layui-inline">\n' +
                                '                                        初始读数：\n' +
                                '                                    </div>\n' +
                                '                                    <div class="layui-inline">\n';
                            for (var j = 0; j < initRead.length; j++) {
                                if (property[i].PROPERTY_TYPE_ID == initRead[j].PROPERTY_TYPE_ID) {
                                    initReadStr += '<div class="layui-input-inline" style="width: auto;">\n' +
                                        '               <span>' + initRead[j].CODE + ' 读数：' + initRead[j].INIT_READ + ' 日期：' + initRead[j].INIT_READ_TIME + '</span>\n' +
                                        '           </div><br>';
                                }
                            }
                            initReadStr += '                    </div>\n' +
                                '                                </div>';
                        }
                    }
                }
                var dw = '';
                if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e') {
                    if (property[i].CHARGE_TYPE == 1) {
                        dw = '元/吨';
                    } else {
                        dw = '元/月';
                    }
                } else if (property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                    if (property[i].CHARGE_TYPE == 1) {
                        dw = '元/度';
                    } else {
                        dw = '元/月';
                    }
                } else if (property[i].PROPERTY_TYPE_ID == '669791dac4894160bc8d79b484519e96' || property[i].PROPERTY_TYPE_ID == '7b05982a081e41deb9b46a1f6f5ed5fa') {
                    if (property[i].DEFAULT_ID == "-1") {
                        if (property[i].LN_UNIT == "1") {
                            dw = '元/㎡';
                        } else {
                            dw = '元/年';
                        }
                    } else {
                        dw = '元/㎡·天';
                    }
                } else {
                    if (property[i].CHARGE_TYPE == 0) {
                        dw = '元/月';
                    } else if (property[i].CHARGE_TYPE == 2) {
                        dw = '元/㎡·天';
                    }
                }

                var jg = property[i].CHARGE_PRICE;
                if (!jg) {
                    jg = 0;
                }
                if (property[i].IS_DEFAULT == 0) {
                    jg = jg + dw;
                } else if (property[i].IS_DEFAULT == 1) {
                    jg = property[i].DEFAULT_PRICE + dw;
                }
                var sfrq = '';
                if (property[i].CHARGE_DATE_TYPE == 0) {
                    sfrq = '提前' + property[i].CHARGE_DATE + '天';
                } else if (property[i].CHARGE_DATE_TYPE == 1) {
                    sfrq = '固定' + property[i].CHARGE_DATE + '号';
                } else if (property[i].CHARGE_DATE_TYPE == 2) {
                    sfrq = '抄表后' + property[i].CHARGE_DATE + '天';
                }
                var sffsStr = '';
                var fkzqStr = property[i].PAY_DATE;
                if (property[i].PROPERTY_TYPE_ID == '669791dac4894160bc8d79b484519e96' || property[i].PROPERTY_TYPE_ID == '7b05982a081e41deb9b46a1f6f5ed5fa') {
                    // fkzqStr = property[i].DATE_START_MONTH + "月" + property[i].DATE_START_DAY + "日 至 " + property[i].DATE_END_MONTH + "月" + property[i].DATE_END_DAY + "日";
                    fkzqStr += "月";
                } else {
                    fkzqStr += "月";
                    sffsStr += '     <div class="layui-form-item">\n' +
                        '                   <div class="layui-inline">\n' +
                        '                       收费方式：' + sffs + '\n' +
                        '                   </div>\n' +
                        '               </div>\n';
                }
                var info = property[i].INFO;
                if (!info) {
                    info = "";
                }
                var str = '<fieldset class="layui-elem-field">\n' +
                    '           <legend>' + property[i].CODE + '</legend>\n' +
                    '           <div class="layui-field-box">\n' +
                    '               <div class="layui-form-item">\n' +
                    '                   <div class="layui-inline">\n' +
                    '                       发票占比：' + property[i].PROPERTY_FPZB + '%\n' +
                    '                   </div>\n' +
                    '               </div>\n';

                var lateFeeStr = ' <div class="layui-form-item">\n' +
                    '                   <div class="layui-inline">\n' +
                    '                       滞纳金比率：当前账单的' + property[i].LATE_FEE + '%\n' +
                    '                   </div>\n' +
                    '               </div>\n' +
                    '               <div class="layui-form-item">\n' +
                    '                   <div class="layui-inline">\n' +
                    '                       滞纳金执行日：付款日后' + property[i].LATE_FEE_DAYS + '天\n' +
                    '                   </div>\n' +
                    '               </div>\n';
                if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                    str += lateFeeStr;
                } else {
                    str += '  <div class="layui-form-item">\n' +
                        '         <div class="layui-inline">\n' +
                        '             计费周期：固定天数：' + property[i].PAY_DAYS + '天\n' +
                        '         </div>\n' +
                        '     </div>\n';
                }


                str += '               <div class="layui-form-item">\n' +
                    '                   <div class="layui-inline">\n' +
                    '                       付款周期：' + fkzqStr + '\n' +
                    '                   </div>\n' +
                    '               </div>\n';
                str += sffsStr;
                str += initReadStr;
                if (property[i].CHARGE_TYPE != "3") {
                    str += '               <div class="layui-form-item">\n' +
                        '                   <div class="layui-inline">\n' +
                        '                       价格：' + jg + '\n' +
                        '                   </div>\n' +
                        '               </div>\n';
                }
                var pStr = "收费";
                if (property[i].CHARGE_TYPE == "3") {
                    pStr = "提醒";
                }
                str += '               <div class="layui-form-item">\n' +
                    '                   <div class="layui-inline">\n' +
                    '                       ' + pStr + '日期：' + sfrq + '\n' +
                    '                   </div>\n' +
                    '               </div>\n' +
                    '               <div class="layui-form-item">\n' +
                    '                   <div class="layui-inline">\n' +
                    '                       付款提醒：付款日前' + property[i].PAY_TX_DAYS + '天\n' +
                    '                   </div>\n' +
                    '               </div>\n' +
                    '               <div class="layui-form-item">\n' +
                    '                   <div class="layui-inline">\n' +
                    '                       备注：' + info + '\n' +
                    '                   </div>\n' +
                    '               </div>\n' +
                    '           </div>\n' +
                    '       </fieldset>';
                $(".property-info").append(str);
            }
        }

        $(".attachments").empty();
        if (!!attachment) {
            for (var i = 0; i < attachment.length; i++) {
                var str = '<div class="layui-input-block">\n' +
                    '          <span>' + (i + 1) + '</span>\n' +
                    '          <span>' + attachment[i].NAME + '</span>\n' +
                    '          <img src="http://' + window.location.host + '/' + attachment[i].PATH + '" title="' + attachment[i].NAME + '">\n' +
                    '          <span><a href="http://' + window.location.host + '/' + attachment[i].PATH + '" target="_blank" class=\"layui-btn layui-btn-mini layui-btn-normal\">下载</a></span>\n' +
                    '      </div>';
                $(".attachments").append(str);
            }
        }

        // 退租信息
        if (checkType == "退租待审核") {
            init.setThrowLease(contract, throwLease);
        }

    },
    // 所选项目为非自有的，隐藏不必要信息
    hideContractInfo: function () {
        $(".cq-hide .layui-inline-short").remove();
        $(".cq-hide .layui-inline-long").remove();
    },
    // 设置退租信息
    setThrowLease: function (contract, throwLease) {
        $(".quote-throw-lease").show();
        if (contract.THROW_LEASE_TYPE == 0) {
            $(".tuizu-type").html("到期退租");
        } else if (contract.THROW_LEASE_TYPE == 1) {
            $(".tuizu-type").html("中途退租");
        }
        $(".tuizu-date").html(contract.THROW_LEASE_DATE);
        $(".tuizu-info").html(contract.THROW_LEASE_INFO);
        $.ajax({
            url: "/contract/findThrowLeaseReasonByIDs",
            data: {ID: contract.THROW_LEASE_REASON},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    var data = res.data;
                    if (!!data) {
                        for (var i = 0; i < data.length; i++) {
                            var str = '<span>' + data[i].NAME + '</span><br>';
                            $(".tuizu-reason").append(str);
                        }
                    }
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });

        var totalStr = '总计：0.00元（总计应收：0.00元 总计应退：0.00元）';

        if (!!throwLease) {
            var ys = 0;
            var yt = 0;
            for (var i = 0; i < throwLease.length; i++) {
                var t = "";
                if (throwLease[i].TYPE == 0) {
                    t = "应收";
                    ys += Number(throwLease[i].MONEY);
                } else if (throwLease[i].TYPE == 1) {
                    t = "应退";
                    yt += Number(throwLease[i].MONEY);
                }
                var str = '<span>' + t + ' ' + Number(throwLease[i].MONEY).toFixed(2) + '元</span> <span>备注：' + throwLease[i].INFO + '</span><br>';
                $(".tuizu-fee").append(str);
            }
            totalStr = '总计：' + (ys - yt).toFixed(2) + '元（总计应收：' + ys.toFixed(2) + '元 总计应退：' + yt.toFixed(2) + '元）';
        }

        $(".tuizu-total").html(totalStr);

    }
};
/**
 * 操作方法集合
 * 使用： operate.function()
 * param: obj传this，调用该方法的对象
 *
 */
var operate = {
    // 审核通过
    pass: function (obj) {
        layer.prompt({title: '请输入备注', value: ' ', formType: 2}, function (text, index) {
            layer.close(index); // 关闭当前提示框
            var i = parent.layer.getFrameIndex(window.name);
            parent.layer.close(i); // 关闭合同详情提示框
            parent.layer.msg("已通过，备注：" + text);   // 父页面弹出已通过
            //alert(checkType)
            //审核通过
            var checkState = 1;
            if ("退租待审核" == checkType) {
                checkState = 1;
            }
            if ("作废待审核" == checkType) {
                checkState = 1;
            }
            if ("变更待审核" == checkType) {
                checkState = 1;
            }
            $.ajax({
                url: "/contract/checkcontractPC",
                data: {id: contractId, checkState: checkState, DETAILS: text, CHECK_STATE: checkType},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });
            window.parent.frames[0].reloadcontractTable();
            /*$.ajax({
                url: "/",
                data: {},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                        parent.layer.close(i);  // 关闭新建合同页面
                        parent.layer.msg("保存成功");   // 父页面弹出保存成功
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg("保存失败");
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });*/
        });
        return false;
    },
    // 审核不通过
    reject: function (obj) {
        layer.prompt({title: '请输入驳回原因', value: ' ', formType: 2}, function (text, index) {
            layer.close(index); // 关闭当前提示框
            var i = parent.layer.getFrameIndex(window.name);
            parent.layer.close(i); // 关闭合同详情提示框
            parent.layer.msg("已驳回，驳回原因：" + text);   // 父页面弹出已驳回
            //审核不通过
            var checkState = 2;
            $.ajax({
                url: "/contract/checkcontractPC",
                data: {id: contractId, checkState: checkState, DETAILS: text, CHECK_STATE: checkType},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });
            window.parent.frames[0].reloadcontractTable();
            /*$.ajax({
                url: "/",
                data: {},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                        parent.layer.close(i);  // 关闭新建合同页面
                        parent.layer.msg("保存成功");   // 父页面弹出保存成功
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg("保存失败");
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });*/
        });
        return false;
    },
    // 打印合同
    print: function (obj) {
        layer.open({
            type: 2,
            title: '打印合同',
            shadeClose: false,
            shade: [0.3],
            maxmin: true, //开启最大化最小化按钮
            area: ['100%', '100%'],
            scrollbar: false, //屏蔽滚动条
            content: 'contract_print.html?type=0&id=' + contractId
        });
    },
    // 关闭窗口
    cancel: function (obj) {
        var i = parent.layer.getFrameIndex(window.name);
        parent.layer.close(i); // 关闭合同详情提示框
    }
};
